package com.ken.app_manager.core;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class DBHelp {

    static Properties properties = new Properties();

    static {
//        获取属性文件输入流
        InputStream in = DBHelp.class.getClassLoader().getResourceAsStream("config.properties");
        try {
//            从文件读取到变量 properties
            properties.load(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取数据库连接
     */
    public static Connection getConnection() throws SQLException, ClassNotFoundException {
        Class.forName(properties.getProperty("driver"));
        Connection connection = DriverManager.getConnection(properties.getProperty("url"), properties);
        return connection;
    }


}
